<?php



class DeliveryService {
	var $name;
	var $upperWeightLimit; //in g
	var $maxWidth;
	var $maxHeight;
	var $maxLength;	
	var $guaranteed = false;
	var $deliveryTimes;//in days
	var $prices;	
	
	function DeliveryService(
		$name,
		$upperWeightLimit,
		$deliveryTimes,
		$prices = null,
		$guaranteed = false,
		$maxWidth = 0,
		$maxHeight = 0,
		$maxLength = 0) {
		$this -> name = $name;
		$this -> upperWeightLimit = $upperWeightLimit;
		$this -> guaranteed = $guaranteed;
		$this -> deliveryTimes = $deliveryTimes;
		$this -> prices = $prices; 
		$this -> maxWidth = $maxWidth;
		$this -> maxHeight = $maxHeight;
		$this -> maxLength = $maxLength;
	}
	
	function setPrices($prices) {
		$this -> prices = $prices;
	}
	
	function getPrices() {
		return $this -> prices;
	}
	
	function getName() {
		return $this -> name;
	}		

	function getDeliveryTimes() {
		return $this -> deliveryTimes;
	}		

	function getUpperWeightLimit() {
		return $this -> upperWeightLimit;
	}	
	
	function getGuaranteed() {
		return $this -> guaranteed;
	}	
	
				
}

class PostageOptions {
	
	var $deliveryServices;
	
	function PostageOptions() {
		$secondClassPacketPrices['100'] = 0.92;
		$secondClassPacketPrices['250'] = 1.20;
		$secondClassPacketPrices['500'] = 1.52;
		$secondClassPacketPrices['750'] = 1.92;
		$secondClassPacketPrices['1000'] = 2.30;
		
		$secondClassPacket = new DeliveryService(
			"Royal Mail - Second Class Packet (Delivery 3-5 days)",
			1000,
			3,
			$secondClassPacketPrices);
		
		$this -> deliveryServices[0] = $secondClassPacket;
			
		$standardParcelPrices['1000'] = 3.85;
		$standardParcelPrices['1500'] = 4.95;
		$standardParcelPrices['2000'] = 5.68;
		$standardParcelPrices['4000'] = 8.24;
		$standardParcelPrices['6000'] = 9.35;
		$standardParcelPrices['8000'] = 10.67;
		$standardParcelPrices['10000'] = 11.45;
		$standardParcelPrices['20000'] = 13.33;
		
		$standardParcel = new DeliveryService(
			"Royal Mail - Standard Parcels (Delivery 3-5 days)",
			20000,
			3,
			$standardParcelPrices);		
			
		$this -> deliveryServices[1] = $standardParcel;					
	}
	
	function getServices($weight) {
		$availableServices = null;
		for ($i = 0; $i < count($this -> deliveryServices); $i++) {
			$deliveryService = $this -> deliveryServices[$i];


			if ( $deliveryService -> getUpperWeightLimit() >= $weight) {
				$servicePrices = $deliveryService -> getPrices();
				foreach ($servicePrices as $weightLimit => $howMuch) {
					if ($weight <= $weightLimit) { 
						$availableServices[$deliveryService -> name] = $howMuch;
						break;
					}
				}
			}
			
		}
		return $availableServices;
	}
	
	
}




?>
